<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title>${appname}-<c:if test="${!empty sessionScope._local_node_session}">${sessionScope._local_node_session.nodeName}-</c:if>${si:ctname("NET_TYPE",sessionScope._netType)}</title>
<%@ include file="/WEB-INF/view/common/css_js_ace.jsp"%>
<link rel="stylesheet"
	href="${ctx}/static/js/lib/ztree/css/zTreeStyle/zTreeStyle.css"
	type="text/css">
<script type="text/javascript"
	src="${ctx}/static/js/lib/ztree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript"
	src="${ctx}/static/js/lib/ztree/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript">
var _rs_image_path = _ctx+"/static/images";
var localNodeId = '${localNode.id}';	
var data=${treeData};
//var data=[{"chkDisabled":"true","id":"a5742281e75a4c9cae751dd373cbb73d","pId":"00000000000000000000000000000000","name":"中央交换节点","code":"00000000 ",open:true,icon:"eval(_rs_image_path+'/node01.png')"},{"id":"6e26a634827c4181a1d9c9c239fc0759","pId":"a5742281e75a4c9cae751dd373cbb73d","name":"长委节点","code":"010000101",icon:_rs_image_path+"/node02.png"},{"chkDisabled":"true","id":"4e801ce551554e1499b0b843c54e91cb","pId":"a5742281e75a4c9cae751dd373cbb73d","name":"湖南节点","code":"430000101"}];

//var data=[{"chkDisabled":"true","id":"a5742281e75a4c9cae751dd373cbb73d","pId":"00000000000000000000000000000000","name":"中央交换节点","code":"00000000 ",open:true},
        //  {"id":"6e26a634827c4181a1d9c9c239fc0759","pId":"a5742281e75a4c9cae751dd373cbb73d","name":"长委节点","code":"010000101"},
          //{"chkDisabled":"true","id":"4e801ce551554e1499b0b843c54e91cb","pId":"a5742281e75a4c9cae751dd373cbb73d","name":"湖南节点","code":"430000101"}];
var setting = {	
		callback: {
			onCheck: getNodeInfo
		},
		check: {
			enable: true,
			chkboxType: { "Y": "s", "N": "ps" }
		},
		click:function(){
			
		},
		data: {
			simpleData: {
				enable: true
			}
		}
};
var zTree;
$(function(){
	zTree = $.fn.zTree.init($("#treeDemo"), setting,data);
	
	
});
function getNodeInfo(event, treeId, treeNode) {
	if(treeNode.id==localNodeId && !treeNode.checked){
		alert("节点【"+treeNode.name+"】拥有绝对的使用网闸权限，不会被取消");
	}
	var nodeId = treeNode.id;
	var pid = treeNode.pId;
	var orgCode = treeNode.orgCode;
	$("#nodeId").val(nodeId);
	var ismgr = "${ismgr}";
	var regionCodesToMgr = "${permission.regionCodesToMgr}";
	if(localNodeId == nodeId && ismgr == "1"){
			$("#edit").removeClass("btn-light").addClass("btn-primary").attr("disabled", null);
			$("#del").removeClass("btn-primary").addClass("btn-light").attr("disabled", "disabled");
	}else if( localNodeId != nodeId && ismgr == "1" && regionCodesToMgr.indexOf(orgCode)!= -1 ){
			$("#edit").removeClass("btn-light").addClass("btn-primary").attr("disabled", null);
			$("#del").removeClass("btn-light").addClass("btn-primary").attr("disabled", null);
	}else{
			$("#edit").removeClass("btn-primary").addClass("btn-light").attr("disabled", "disabled");
			$("#del").removeClass("btn-primary").addClass("btn-light").attr("disabled", "disabled");
	}
    $.ajax({
		   type: "GET",
		   dataType:"html",
		   cache: false,
		   url: _ctx + "/registry/node_info_get.do",
		   data: {id:treeNode.id},
		   success: function( content ){
			   $('#data').html( content ); 
		   },
		   error:function(){
			   ui.msg('信息加载错误', 0);
		   }
	});
}
//arrayData数组对象，prop属性名称，value属性值
//根据prop属性名称，value属性值 找出数组中对应的对象
function getNode(arrayData,prop,value){
	if(arrayData==null || arrayData.length<=0){
		return null;
	}
	for(var i=0;i<arrayData.length;i++){
		if(arrayData[i][prop]==value){
			return arrayData[i];
		}
		
	}
	return null;
}

	function gapConfigAdd(userId,userName){
		ui.confirm("确定更改网闸权限配置?",function(result){
			var nodes = zTree.getCheckedNodes(true);
			var addCodes=[];
			var deleteCodes=[];
			//循环遍历data数据，找出初始没有勾选后面勾选的  找出初始勾选后面没有勾选的
			for(var i=0;i<data.length;i++){
				var selectNode=getNode(nodes,"nodeCode",data[i]["nodeCode"]);
				if(selectNode!=null && selectNode.checked && !data[i].checked){
					addCodes.push(data[i]["nodeCode"]);//初始未选中，后面选中
				}else if(selectNode==null && data[i].checked){
					deleteCodes.push(data[i]["nodeCode"]);//初始选中，后面没有选中
				}
				
			}
			//封装参数
			$.ajax({
				   type: "post",
				   dataType:"json",
				   cache: false,
				   url: _ctx + "/gap/gap_config_update.do",
				   data:{addCodes:addCodes.join(","),deleteCodes:deleteCodes.join(",")},
				   success: function( result ){
					   if(result["result"]==0){//如果更新成功
						   ui.msg('保存成功',1);
					   }else{//如果更新失败
						   ui.msg('保存失败',0);
					   }
					   location.reload();
				   },
				   error:function(){
				   }
			});
		});
	}
function gapInfoUpate(){
	 $.ajax({
		   type: "post",
		   dataType:"json",
		   cache: false,
		   url: _ctx + "/gap/gap_info_get.do",
		   success: function(result){
			  if(result!=null){
				  $("#inputForm #id").val(result["id"]);
				   $("#inputForm #ftpIp").val(result["ftpIp"]);
				   $("#inputForm #ftpPort").val(result["ftpPort"]);
				   $("#inputForm #ftpUser").val(result["ftpUser"]);
				   $("#inputForm #ftpPwd").val(result["ftpPwd"]);
				   $("#inputForm #ftpHome").val(result["ftpHome"]);
				   $("#inputForm #reMark").val(result["reMark"]);
			  }
				$('#inputForm input').tooltip();
				//表单验证
				$('#inputForm').checkForm();
			   $('#myModal').modal('show');
			   
		   },
		   error:function(){
		   }
	});
}

function saveData(){
	if($('#inputForm').checkFormResult()){
		ui.confirm("确定更改网闸信息配置?",function(result){
		$('#inputForm').ajaxSubmit({
				  url: _ctx +"/gap/gap_info_update.do",
			        type: "post",
			        dataType:"json",
			        beforeSubmit: function(){
			           	$("#sbmBtn").attr("disabled","disabled");
			        },
			        clearForm: false,
			        resetForm: false,
			        success: function(resp){
			        	if(resp.result == '0' ){
			        		ui.msg(resp.msg, 1);
			        		$('#myModal').modal('hide');
			        		location.reload();
			        	}else{
			        		ui.msg(resp.msg, 0);
			        	}
			        	$("#sbmBtn").removeClass("disabled").attr("disabled",null);
			        },
			        error:function(resp){
			        	ui.msg('请求发送失败', 0);
			    		$("#sbmBtn").removeClass("disabled").attr("disabled",null);
			        }
			});
		});
	}
	
}

	function insertOrUpdate() {  
	   var id=1;
	   var gapowner = $("input[name='optionsRadios']:checked").val();
      
		$.ajax({
			type : "GET",
			dataType : "json",
			cache : false,
			url : _ctx + "/registry/ga_data_insertOrUpdate.do",
			data : {
			    id :id,
				gapOwner : gapowner
			},
			success : function(resp) {
	           if(resp.status == '1' ){
	        		ui.msg(resp.msg, 1);
	        		
	        		location.reload();
	        	}else{
	        		ui.msg(resp.msg, 0);
	        	}
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	
</script>
<style type="text/css">
div.zTreeDemoBackground {
	width: 340px;
	height: 340px;
	text-align: left;
}

ul.ztree {
	margin-top: 10px;
	border: 1px solid #CCC;
	height: 300px;
	overflow-y: auto;
	overflow-x: auto;
	font-size: 13px;
}

.ztree * {
	padding: 0;
	margin: 0;
	font-size: 13px;
	font-family: Verdana, Arial, Helvetica, AppleGothic, sans-serif;
}

.ztree li span {
		line-height: 24px;
		margin-right: 2px;
	}
	.ztree li span.button.switch {
		width: 18px;
		height: 22px;
	}
	.ztree li a {
	height: 24px;
	}
	.ztree li a.curSelectedNode {
	height: 24px;
	}
	
	.ztree li span.button {
		line-height: 0;
		margin: 0;
		width: 24px;
		height: 24px;
		display: inline-block;
		border: 0 none;
		cursor: pointer;
		outline: none;
	}
	
		
	@media only screen and (max-width:992px) {
		.profile-info-name {
			width: 80px
		}
		.profile-info-value {
			margin-left: 90px
		}
		.profile-user-info-striped .profile-info-name {
			position: static;
			width: auto;
			text-align: left;
			padding: 6px 0 6px 10px
		}
		.profile-user-info-striped .profile-info-value {
			margin-left: 10px
		}
	}
	
	@media only screen and (max-width:992px) {
		.user-profile .memberdiv {
			width: 50%;
			margin-left: 0;
			margin-right: 0
		}
	}
</style>
</head>
<body>
	<%@ include file="/WEB-INF/view/common/topbar.jsp"%>
	<div class="main-container" id="main-container">
		<div id="myModal" class="modal fade" role="dialog" tabindex="-1"
			aria-labelledby="查看" aria-hidden="false">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="widget-header" style="margin-bottom: 3px;">
						<h3 class="smaller">网闸信息</h3>
					</div>
					<div>
						<form class="form-horizontal" role="form" id="inputForm" action=""
							method="post">
							<input type="hidden" name="id" id="id" />
							<div class="form-group">
								<div class="col-sm-3 control-label no-padding-right"
									for="form-field-1">FTP地址 *</div>
								<div class="col-sm-9">
									<input type="text" class="col-xs-10 col-sm-5" value=""
										name="ftpIp" id="ftpIp" datatype="require|ip"
										placeholder="请输入FTP地址" msg="请输入FTP地址|请输入正确的FTP地址"
										title="必填项,FTP地址" />
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-3 control-label no-padding-right"
									for="form-field-1">端口号 *</div>
								<div class="col-sm-9">
									<input type="text" class="col-xs-10 col-sm-5" value=""
										name="ftpPort" id="ftpPort" datatype="require|number"
										placeholder="请输入端口号" msg="请输入端口号|请输入正确的端口号" title="必填项,端口号" />
								</div>
							</div>
							<div class="space-4"></div>
							<div class="form-group">
								<div class="col-sm-3 control-label no-padding-right">用户名*</div>
								<div class="col-sm-9">
									<input type="text" class="col-sm-5" placeholder="请输入用户名"
										name="ftpUser" id="ftpUser" datatype="require" msg="请输入用户名"
										title="必选项，用户名" />
								</div>
							</div>
							<div class="space-4"></div>
							<div class="form-group">
								<div class="col-sm-3 control-label no-padding-right">密码*</div>
								<div class="col-sm-9">
									<input type="text" class="col-xs-10 col-sm-5 search-query"
										value="" name="ftpPwd" id="ftpPwd" datatype="require"
										placeholder="请输入密码" msg="请输入密码" title="必填项,密码" />&nbsp;
								</div>
							</div>
							<div class="space-4"></div>
							<div class="form-group">
								<div class="col-sm-3 control-label no-padding-right"
									for="form-field-1">主目录 *</div>
								<div class="col-sm-9">
									<input type="text" class="col-xs-10 col-sm-5" value=""
										name="ftpHome" id="ftpHome" datatype="require"
										placeholder="请输入主目录" msg="请输入主目录" title="必填项,请输入主目录" />
								</div>
							</div>
							<div class="space-4"></div>
							<div class="form-group">
								<div class="col-sm-3 control-label no-padding-right"
									for="form-field-2">备注</div>
								<div class="col-sm-9">
									<textarea class="col-sm-5" placeholder="请输入备注" name="reMark"
										id="reMark" title="备注"></textarea>
								</div>
							</div>
							<hr>
						</form>
					</div>
					<div class="modal-footer wizard-actions">
						<button class="btn btn-danger btn-sm pull-left"
							data-dismiss="modal">
							<i class="icon-remove"></i> 关闭
						</button>
						<button class="btn btn-sm btn-info" id="sbmBtn"
							onclick="saveData()">
							<i class="icon-ok bigger-110"></i> 保存
						</button>
					</div>
				</div>
			</div>
		</div>
		<div class="main-container-inner">
			<%@ include file="/WEB-INF/view/common/sidebar.jsp"%>
			<div class="main-content">
				<div class="breadcrumbs" id="breadcrumbs">
					<ul class="breadcrumb">
						<li><i class="icon-home home-icon"></i> <a
							href="javascript:void(0);">首页</a></li>
						<li><a href="javascript:void(0);">平台基础配置</a></li>
						<li class="active">网闸配置</li>
					</ul>
				</div>
				<div class="page-content" style="height: 30px;">
					<div class="row">
						<div class="col-xs-12">
							<div>
							<c:if test="${hasGap eq true }">
								<div class="col-xs-12">
									<div class="col-sm-6">
										<div class="table-responsive">

											<h5 class="header blue lighter smaller">
												<span class="span7"> <i class="icon-th-large"> </i>
													&nbsp;&nbsp;网闸基本信息&nbsp;&nbsp;&nbsp;&nbsp;</span>
												<!-- /span -->

												<span class="span5"> <label
													class="pull-middle inline"> <input type="hidden"
														id="nodeId" name="nodeId" value=""> <input
														type="hidden" id="localNodeId" name="localNodeId" value="">
														<!-- <button type="button" class="btn btn-sm btn-primary"
															onclick="gapInfoUpate();" id="add">
															<i class="icon-pencil bigger-120"></i>修改
														</button> --><i class='red'>${errorMsg }</i>
												</label> </span>

												<!-- /span -->
											</h5>
											<div class="profile-user-info profile-user-info-striped">
											<div class="profile-info-row">
												<div class="profile-info-name">FTP地址</div>
												<div class="profile-info-value">
													<span class="editable">${vo.ftpIp}&nbsp;</span>
												</div>
											</div>
											<div class="profile-info-row">
												<div class="profile-info-name">端口号</div>
												<div class="profile-info-value">
													<span class="editable">${vo.ftpPort}&nbsp;</span>
												</div>
											</div>
											<div class="profile-info-row">
												<div class="profile-info-name">用户名</div>
												<div class="profile-info-value">
													<span class="editable">${vo.ftpUser}&nbsp;</span>
												</div>
											</div>
										<!--  	<div class="profile-info-row">
												<div class="profile-info-name">密码</div>
												<div class="profile-info-value">
													<span class="editable">${vo.ftpPwd}&nbsp;</span>
												</div>
											</div>-->
											<div class="profile-info-row">
												<div class="profile-info-name">主目录</div>
												<div class="profile-info-value">
													<span class="editable">${vo.ftpHome}&nbsp;</span>
												</div>
											</div>
											<div class="profile-info-row">
												<div class="profile-info-name">修改时间</div>
												<div class="profile-info-value">
													<span class="editable">${si:fmtDate(vo.mTime)}&nbsp;</span>
												</div>
											</div>
											<div class="profile-info-row">
												<div class="profile-info-name">备注</div>
												<div class="profile-info-value">
													<span class="editable">${vo.reMark}&nbsp;</span>
												</div>
											</div>
											</div>
										</div>
									</div>
									<div class="col-sm-6">
										<div class="table-responsive">

											<h5 class="header blue lighter smaller">
												<span class="span7"> <i class="icon-th-large"> </i>
													&nbsp;&nbsp;分配网闸使用权限&nbsp;&nbsp;&nbsp;&nbsp;</span>
												<!-- /span -->

												<span class="span5"> <label
													class="pull-middle inline"> <input type="hidden"
														id="nodeId" name="nodeId" value=""> <input
														type="hidden" id="localNodeId" name="localNodeId" value="">
														<button type="button" class="btn btn-sm btn-primary"
															onclick="gapConfigAdd();" id="add">
															<i class="icon-save bigger-120"></i>保存
														</button> <i class='red'>${errorMsg }</i>
												</label> </span>

												<!-- /span -->
											</h5>

											<div id="treeDiv">
												<div class="zTreeDemoBackground">
													<ul id="treeDemo" class="ztree"></ul>
												</div>
											</div>
										</div>
									</div>
								</div>
							</c:if>	
								<div class="page-content">
									<div class="row">
										<div class="col-xs-12">
											<h5 class="header blue lighter smaller">
												<span class="span7"> <i class="icon-th-large"> </i>
													&nbsp;&nbsp;设置本地节点默认使用的网闸节点&nbsp;&nbsp;&nbsp;&nbsp;</span>
												<!-- /span -->

												<span class="span5"> <label
													class="pull-middle inline">
														<button 
															onclick="insertOrUpdate()"
																<c:if test="${fn:length(get_user_conf)<=0}">class="btn btn-light"  disabled="disabled"</c:if>
																<c:if test="${fn:length(get_user_conf)>0}">class="btn btn-sm  btn-primary"</c:if>
															>
															<i class="icon-save bigger-120"></i>保存
														</button> <span class="lbl"></span> </label> </span>
												<!-- /span -->
											</h5>

											<div class="container">
												<c:forEach var="vo" items="${get_user_conf}">
													<tr>
														<td><div class="radio-inline">
														
																<label> 
																<input type="radio" name="optionsRadios" value="${vo.gapOwner}" 
																<c:if test="${vo.status=='1' }">checked</c:if>
																/>
																	${si:nodeName(vo.gapOwner) }
																</label>
																
															</div></td>
													</tr>
												</c:forEach>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
